define(['app','assets/js/jquery-weui'],function(app,weui){return {module: function($scope, $http, eventBusService, httpService, params) {
	//查询主校区和分校区
	httpService.post(app.urls.unit_selectSchoolAndAttach,{},function(data){
		if("0000" === data.code){
			$scope.unitList = data.data;
		}else{
			alert(data.msg);
		}
	});
	//查询年级
	$scope.findGrade = function(){
		$scope.select();
		httpService.post(app.urls.grade_selectCenterGrade,{"fk_unit":$scope.form.fk_unit},function(data){
			if("0000" === data.code){
				$scope.gradeList = data.data;
			}else{
				alert(data.msg);
			}
		});
	}
	//获取班级
	$scope.findClass=function(){
		$scope.select();
		httpService.post(app.urls.class_selectClassName,{"fk_unit":$scope.form.fk_unit,"fk_grade":$scope.form.fk_grade,"status":'0'},function(data){
			if("0000" === data.code){
				$scope.classList = data.data;
			}else{
				alert(data.msg);
			}
		});
	}
	//查询班级列表
	$scope.rows = [];
	$scope.form.find = false;
	$scope.form.empty = false;
	$scope.find = function(){
		$scope.form.list='list';
		httpService.postpage(app.urls.class_select,$scope.form,function(data){
			if("0000" === data.code){
				if(data.data.length <= 0) {
					$scope.form.empty = true;
					$scope.form.find = false;
	            }else{
	            	if(data.page.pages == 1 || data.page.pages ==  $scope.page.current) {
	            		$scope.form.empty = false;
						$scope.form.find = false;
	            	}else{
						$scope.form.empty = false;
						$scope.form.find = true;
	            	}
					$scope.rows = $scope.rows.concat(data.data);
				}
    		}else{
    			alert(data.msg);
    		}
		});
	}
	httpService.post(app.urls.role_selectType,{},function(data){
		if("0000" === data.code){
			$scope.form.userrole = data.data[0].type;
			$scope.find();
		}else{
			alert(data.msg);
		}
	});
	$scope.select = function(){
		$scope.rows = [];
    	$scope.page.current = 1;
    	$scope.find();
    }
	//返回
	$scope.goback = function(){
		window.history.back();
	}
	//接收数据刷新
	eventBusService.subscribe('modules.mobile.load', function(event,data) {
		$scope.select();
	});
	$(document.body).infinite().on("infinite", function () {
		if(!$scope.form.find){
			return;
		}
		$scope.form.find = false;
        $scope.page.current++; //页数
        setTimeout(function() {
            $scope.find();
        }, 1500);   //模拟延迟
	});
}}});